﻿using UnityEngine;
using System.Collections;

public class EventMsg : MonoBehaviour {

    public string m_strTimedEventID;
    public EVENT_CHOICE m_EventChoice;

	// Use this for initialization
	void Start () {
        GameTime.TimeSpeed_Pause();
        transform.localPosition = new Vector3(-0.25f, 2);

        //switch (m_iRealEventID)
        //{
        //    case 0:
        //        MsgLabeling(FindDic("RiotComing", "Name"), FindDic("RiotComing", "Desc"), EVENT_CHOICE.CONFIRM);
        //        break;

        //    case 1:
        //        MsgLabeling(FindDic("Retreat", "Name"), FindDic("Retreat", "Desc"), EVENT_CHOICE.CONFIRM);
        //        break;

        //    case 2:
        //        MsgLabeling(FindDic("Attack", "Name"), FindDic("Attack", "Desc"), EVENT_CHOICE.CHOICE_STATE, FindDic("Attack", "Choice0"), FindDic("Attack", "Choice1"));
        //        break;

        //    case 3:
        //        MsgLabeling(FindDic("Attack", "Name"), FindDic("Attack", "Desc"), EVENT_CHOICE.CHOICE_STATE, FindDic("Attack", "Choice0"), FindDic("Attack", "Choice1"));
        //        break;
        //}

        TimedEventInitializing(m_strTimedEventID);
	}

    void MsgLabeling(string strSubject, string strContent, EVENT_CHOICE Choice, string strChoice0 = null, string strChoice1 = null)
    {
        transform.FindChild("Subject").GetComponent<UILabel>().text = strSubject;
        transform.FindChild("Contents").GetComponent<UILabel>().text = strContent;
        switch (Choice)
        {
            case EVENT_CHOICE.CHOICE_STATE:
                transform.FindChild("Choice0").FindChild("Label").GetComponent<UILabel>().text = strChoice0;
                transform.FindChild("Choice1").FindChild("Label").GetComponent<UILabel>().text = strChoice1;
                m_EventChoice = EVENT_CHOICE.CHOICE_STATE;
                break;

            case EVENT_CHOICE.CONFIRM:
                transform.FindChild("Choice0").gameObject.SetActive(false);
                transform.FindChild("Choice1").FindChild("Label").GetComponent<UILabel>().text = "Confirm";
                m_EventChoice = EVENT_CHOICE.CONFIRM;
                break;

            case EVENT_CHOICE.YES_OR_NO:
                transform.FindChild("Choice0").FindChild("Label").GetComponent<UILabel>().text = "Yes";
                transform.FindChild("Choice1").FindChild("Label").GetComponent<UILabel>().text = "No";
                m_EventChoice = EVENT_CHOICE.YES_OR_NO;
                break;
        }
    }

    string FindDic(string strID, string FindThing)
    {
        string strBack;

        for (int i = 0; i < xmlLoader.GetInstance().m_XML_Events.Count; ++i)
        {
            xmlLoader.GetInstance().m_XML_Events[i].TryGetValue("ID", out strBack);
            if (strBack == strID)
            {
                xmlLoader.GetInstance().m_XML_Events[i].TryGetValue(FindThing, out strBack);
                return strBack;
            }
        }

        //xmlLoader.GetInstance().m_XML_Events[iID].TryGetValue(FindThing, out strBack);
        //return strBack;


        return null;        
    }
	
	// Update is called once per frame
	void Update () {
	    
	}

    void TimedEventInitializing(string iEventIdx)
    {
        switch(System.Convert.ToInt32(FindDic(iEventIdx, "CHOICE"))) // Case 0  - Yes or No, case 1 - Confirm, case 2 - Choice State;
        {
            case 0:
                MsgLabeling(FindDic(iEventIdx, "Name"), FindDic(iEventIdx, "Desc"), EVENT_CHOICE.YES_OR_NO);
                break;

            case 1:
                MsgLabeling(FindDic(iEventIdx, "Name"), FindDic(iEventIdx, "Desc"), EVENT_CHOICE.CONFIRM);
                break;

            case 2:
                MsgLabeling(FindDic(iEventIdx, "Name"), FindDic(iEventIdx, "Desc"), EVENT_CHOICE.CHOICE_STATE, FindDic(iEventIdx, "Choice0"),  FindDic(iEventIdx, "Choice1"));
                break;
        }
    }
}
